var adcontentForm = function () {
    return {
        //main function to initiate the module
        init: function () {
			$.validator.addMethod(
				"regex", 
				function(value, element, params) {
					var reg = new RegExp(params);
					//console.log('value:'+value+' , params: '+params+' , result: '+reg.test(value));
					return reg.test(value);
				}, 
				"Did not pass the regular verification"
			);

            var form1 = $('#adcontentForm');
            var error1 = $('.alert-error', form1);
            var success1 = $('.alert-success', form1);

            form1.validate({
                errorElement: 'span', //default input error message container
                errorClass: 'help-inline', // default input error message class
                focusInvalid: false, // do not focus the last invalid input
                ignore: "",
                rules: {
                    username: {
                        regex: '^[a-zA-Z]{1}\\w{4,19}$',
                        required: true,
                    },
                    password: {
                        required: true,
                       	regex: '^[\\s\\S]{5,20}$',
                    },
                    password_re: {
						required: true,
						equalTo: "input[name='password']"
                    },
                    role: {
                        required: true,
                    },
                    phone: {
                        required: true
                    },
                    email: {
                        required: true,
						email   : true
                    }				
                },
				messages: {
					username: {
						required:  vMessage.username_required,
						regex: vMessage.username_regex
					},
					password: {
						required:  vMessage.password_required,
						regex: vMessage.password_regex
					},
					password_re: {
						required:  vMessage.password_re_required,
						regex: vMessage.password_re_regex
					},
					 role: {
                        required: vMessage.role_required,
                    },
                    phone: {
                        required: vMessage.phone_regex,
                    },
                    email: {
                        required: vMessage.email_required,
						email   : vMessage.email_email
                    }		
				},
                invalidHandler: function (event, validator) {
                    success1.hide();
                    error1.show();
                    App.scrollTo(error1, -200);
                },

                highlight: function (element) {
                    $(element).closest('.help-inline').removeClass('ok');
                    $(element).closest('.control-group').removeClass('success').addClass('error');
                },

                unhighlight: function (element) {
                    $(element).closest('.control-group').removeClass('error');
                },
            });
        }

    };

}();